/* autor Konjkov.VV@gmail.com */

#include <string>
#include <iostream>

#include "Syncctl.h"
#include "Sqlerr.h"

int main(int argc, char *argv[])
{
Syncctl s;

try {
    if (argc==3 && std::string(argv[1]) == "system") {
             if (std::string(argv[2]) == "install")		{s.system_install();}
        else if (std::string(argv[2]) == "uninstall")		{s.system_uninstall();}
        else if (std::string(argv[2]) == "update")		{s.system_update();}
        else if (std::string(argv[2]) == "status")		{s.system_status();}
    } else if (argc>=3 && std::string(argv[1]) == "node") {
             if (std::string(argv[2]) == "add")			{s.node_add(argv[3]);}
        else if (std::string(argv[2]) == "remove")		{s.node_remove(argv[3]);}
        else if (std::string(argv[2]) == "reset")		{s.node_reset(argv[3]);}
        else if (std::string(argv[2]) == "list")		{s.node_list();}
    } else if (argc==4 && std::string(argv[1]) == "table") {
             if (std::string(argv[2]) == "add")			{s.table_add(std::string(argv[3]));}
        else if (std::string(argv[2]) == "update")		{s.table_update(std::string(argv[3]));}
        else if (std::string(argv[2]) == "remove")		{s.table_remove(std::string(argv[3]));}
        else if (std::string(argv[2]) == "dwatch-on")		{s.table_dwatch_on(std::string(argv[3]));}
        else if (std::string(argv[2]) == "dwatch-off")		{s.table_dwatch_off(std::string(argv[3]));}
    } else if (argc==5 && std::string(argv[1]) == "data") {
             if (std::string(argv[2]) == "prepare")		{s.data_prepare(argv[4]);}
        else if (std::string(argv[2]) == "update")		{s.data_update(argv[4]);}
    } else if (argc>=5 && std::string(argv[1]) == "prepared") {
             if (std::string(argv[2]) == "set")			{s.prepared_set(argv[5], argv[3]);}
        else if (std::string(argv[2]) == "get")			{std::cout << s.prepared_get(argv[4]) << std::endl;}
    } else if (argc>=5 && std::string(argv[1]) == "updated") {
             if (std::string(argv[2]) == "set")			{s.updated_set(argv[5], argv[3]);}
        else if (std::string(argv[2]) == "get")			{std::cout << s.updated_get(argv[4]) << std::endl;}
    } else {
        s.print_usage();
    }
} catch (Sqlerr& e) {
    e.Errmessage();
}
    return 0;
}
